package com.hhd.pdf;

import com.hhd.pdf.component.PdfComponentDelegate;
import com.hhd.pdf.context.GeneratorContext;
import org.dom4j.Document;
import org.dom4j.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class DefaultPdfGenerator extends AbstractPdfGenerator {

    @Autowired
    PdfComponentDelegate pdfComponentDelegate;

    @Override
    public List<com.itextpdf.text.Element> doGenerate(GeneratorContext context) {
        Document xmlDocument = context.getXmlDocument();
        Element rootElement = xmlDocument.getRootElement();
        context = context.rootRuntime(rootElement);
        return pdfComponentDelegate.genElements(context);
    }
}
